<script>
import ChildComponent from './ChildComponent.vue';
import {mapActions, mapState} from "vuex"; // 引入子组件
export default {
  name: "GrandpaComponent",
  components: {
    ChildComponent
  },
  computed: {
    ...mapState(['message']), // 通过 mapState 获取状态
  },
  methods: {
    ...mapActions(['updateMessageAsync']), // 通过 mapActions 映射 actions
  }
}
</script>

<template>
  <div>
    <h1>Grandpa Component</h1>
    <p>{{ message }}</p>
    <button @click="updateMessageAsync('来自爷组件的异步消息')">Update Message Async</button>
    <ChildComponent /> <!-- 嵌套子组件 -->
  </div>
</template>

<style scoped>

</style>
